<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    <script src="//cdn.jsdelivr.net/sockjs/1.0.0/sockjs.min.js"></script>
    <script type="text/javascript">

            const sock = new SockJS('http://localhost:8081/ws');
            sock.onopen = function() {
                console.log('open');

                sock.send('test');
            };
            sock.onmessage = function(e) {
                console.log('message', e.data);
            };
            sock.onclose = function() {
                console.log('close');
            };
            //
            //sock.close();

    </script>

</head>
<body>

<div id="sse">
    <a href="javascript:WebSocketTest()">运行 WebSocket</a>
</div>

</body>
</html>